import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;
import java.util.Scanner;

public class Add_Student {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入姓名：");
        String newName = sc.next();

        System.out.print("请输入性别：");
        String newSex = sc.next();

        System.out.print("请输入手机号：");
        String phone = sc.next();

        System.out.print("请输入email：");
        String email = sc.next();

        System.out.print("请输入qq：");
        String qq= sc.next();

        System.out.print("请输入wechat：");
        String wechat = sc.next();

        System.out.print("请输入年级：");
        int grade = sc.nextInt();

        System.out.print("请输入入学时间(格式:yyyy-mm-dd)：");
        String enterDate = sc.next();

        System.out.print("请输入来自城市：");
        String fromCity = sc.next();

        System.out.print("请输入生日(格式:yyyy-mm-dd)：");
        String birthday = sc.next();

        System.out.print("请输入地址：");
        String address = sc.next();

        System.out.print("请输入密码：");
        String pass = sc.next();
        Date de = java.sql.Date.valueOf(enterDate);
        Date db = java.sql.Date.valueOf(birthday);
        Connection con = null;
        PreparedStatement ps = null;
        String sql = "insert into s_student(sname,sex,telephone,email,qq,wechat,gradeid,enterdate,fromcity,birthday,address,pass)" +
                "values(?,?,?,?,?,?,?,?,?,?,?,?)";
        try {
            con = DBUtil.getConnection();
            ps = con.prepareStatement(sql);
            ps.setString(1,newName);
            ps.setString(2,newSex);
            ps.setString(3,phone);
            ps.setString(4,email);
            ps.setString(5,qq);
            ps.setString(6,wechat);
            ps.setInt(7,grade);
            ps.setDate(8, (java.sql.Date) de);
            ps.setString(9,fromCity);
            ps.setDate(10, (java.sql.Date) db);
            ps.setString(11,address);
            ps.setString(12,pass);
            int i = ps.executeUpdate();
            System.out.println(i);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            DBUtil.close(null,ps,con);
        }
    }
}
